--抄底形态 ma13上穿ma55，需配合历史走势形态，大圆底，并且没有放量情况。
create or replace function getstchaodi(days int) returns setof record as
$$
declare
rec record;
begin
  for rec in EXECUTE '
select b."date",b.code,b.macd,
	s."name",s.industry from basic_data b  left join stocks s  on b.code=s.code 
where 
to_date(date,''YYYY-MM-DD'') = getwd(current_date,'||days||')
	and ma13 >= ma55
	and strpos(s."name",''ST'')=0
	and s."timeToMarket" <>0 and to_date(to_char(s."timeToMarket",''99999999''),''YYYYMMDD'') < current_date-180
  	and (select ma13 from basic_data where to_date(date,''YYYY-MM-DD'') = getwd(current_date,'||days+1||') and code=b.code ) <  (select ma55 from basic_data where to_date(date,''YYYY-MM-DD'') = getwd(current_date,'||days+1||') and code=b.code )
	--order by macd::float8
	;
	' loop
    return next rec;
  end loop;
return;
end
$$
language 'plpgsql';